package iechecs;

public class Couple<X, Y>
{

    private final X x;
    private final Y y;

    private Couple(X x, Y y)
    {
        this.x = x;
        this.y = y;
    }

    public X x()
    {
        return x;
    }

    public Y y()
    {
        return y;
    }

    @Override
    public String toString()
    {
        return "(" + x + "," + y + ")";
    }

    public static <X, Y> Couple<X, Y> Paire(X x, Y y)
    {
        return new Couple(x, y);
    }

//    public static <X> Couple<X, X> Couple(X[] source) {
//        assert source.length == 2 : "Pair is built on a two-element array; got " + source.length;
//        return Couple(source[0], source[1]);
//    }
    @Override
    public boolean equals(Object o)
    {
        return o instanceof Couple && ((Couple) o).x.equals(x) && ((Couple) o).y.equals(y);
    }

    @Override
    public int hashCode()
    {
        return x.hashCode() * 2 + y.hashCode();
    }
}

